//
//  LoginViewController.m
//  WE
//
//  Created by 然然 on 15/11/16.
//  Copyright © 2015年 然然. All rights reserved.
//

#import "LoginViewController.h"
#import "RegistViewController.h"
#import "WeViewController.h"
#import "TabBarController.h"

@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet UIButton *ToRegistButton;

@property (weak, nonatomic) IBOutlet UITextField *userNameLable;

@property (weak, nonatomic) IBOutlet UITextField *passwordLable;


@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setUpSubViews];
    
}



-(void)setUpSubViews
{
    self.ToRegistButton.layer.cornerRadius = 5;
}






- (IBAction)loginButtonAction:(id)sender {
   [AVUser logInWithUsernameInBackground:self.userNameLable.text password:self.passwordLable.text block:^(AVUser *user, NSError *error) {
       if (user) {
           NSLog(@"登录成功");
           AVUser *currentUser = [AVUser currentUser];
           if (currentUser != nil) {
               TabBarController *tabBarVC = [[TabBarController alloc] init];
               [self presentViewController:tabBarVC animated:YES completion:nil];
           } else {
               //缓存用户对象为空时，可打开用户注册界面…
           }
       } else
       {
           NSLog(@"登录失败  %@", error);
       }
   }];
}


- (IBAction)toRegistButtonAction:(id)sender {
    
    RegistViewController *registVC = [[RegistViewController alloc] initWithNibName:@"RegistViewController" bundle:[NSBundle mainBundle]];
    [self presentViewController:registVC animated:YES completion:nil];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
